package com.sdruixinggroup.mondayb2b.interfaces;

import android.util.Log;

import com.google.gson.reflect.TypeToken;
import com.sdruixinggroup.mondayb2b.utils.GsonUtils;
import com.zhy.http.okhttp.callback.Callback;

import okhttp3.Response;

/**
 * Created by 00029935 on 2017/1/10.
 */

public abstract class ObjectCallBack<T>  extends Callback<T> {

    private TypeToken<T> type;

    public ObjectCallBack(TypeToken<T> type) {
        this.type = type;
    }

    @Override
    public T parseNetworkResponse(Response response, int id) throws Exception {

            String json = response.body().string();
            T result = null;
            if (json != null) {
                Log.d("parseNetworkResponse","response=" + json.replaceAll(" ", "").replaceAll("\n", ""));
                result = GsonUtils.fromJson(json, type);
            }


            return result;
}

}



